package mrusanov.util.swing

trait EventProducer[T] {
  private var consumers:Vector[EventConsumer[T]] = Vector()

  def addEventConsumer(consumer:EventConsumer[T]) {
    consumers :+= consumer
  }

  def removeEventConsumer(consumer:EventConsumer[T]) {
    consumers = consumers.filterNot(_ == consumer)
  }

  def notifyConsumers(eventObject:T) {
    val event = new Event(eventObject)
    consumers.foreach(_.consumeEvent(event))
  }
}
